import { InputQuestion, QuestionBase, SelectQuestion, TextQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api } from '@/config/api/archives';
import { BOX_STATUS_COLOR } from '@/filters/color';
import { regExp } from '@/utils/regExp';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'code',
        label: '档案盒编码',
        value: null,
        placeholder: '请输入'
      }),
      new SelectQuestion({
        key: 'status',
        label: '档案盒状态',
        value: [],
        defaultValue: [],
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'BOX_STATUS'
        }
      }),
      new SelectQuestion({
        key: 'folderId',
        label: '存放地点',
        value: [],
        type: 'tree',
        state: {
          url: Api.folderTree,
          expandAll: true,
          multiple: true,
          protType: 'post',
          asParentId: 'parentId',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children',
          params: {
            dkey: 'folderId'
          }
        }
      }),
      new SelectQuestion({
        key: 'typeId',
        label: '档案类型',
        prompt: '请选择',
        value: [],
        type: 'tree',
        state: {
          url: Api.typeTree,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children',
          multiple: true,
          expandAll: true
        }
      })
    ];
    return questions;
  }
  getTables() {
    const setAction = (status) => {
      const btnForm: QuestionBase<any>[] = [
        status == 2
          ? new SelectQuestion({
              key: 'changeStatus',
              label: '档案盒状态',
              value: 0,
              required: true,
              prompt: '请选择',
              options: [
                {
                  label: '关闭',
                  value: 0
                }
              ]
            })
          : status == 0
          ? new SelectQuestion({
              key: 'changeStatus',
              label: '档案盒状态',
              value: 2,
              required: true,
              prompt: '请选择',
              options: [
                {
                  label: '使用中',
                  value: 2
                }
              ]
            })
          : null,
        new InputQuestion({
          key: 'reason',
          label: '状态变更原因',
          required: true,
          reg: regExp.len30,
          prompt: '状态变更原因不能为空，长度在20个字符之内',
          value: null
        }),
        new InputQuestion({
          key: 'startPartNo',
          label: '起始件号',
          prompt: '请输入',
          value: null
        }),
        new InputQuestion({
          key: 'endPartNo',
          label: '终止件号',
          prompt: '请输入',
          value: null
        })
      ];
      return {
        type: 'layerFrom',
        text: '状态变更',
        class: 'text-primary',
        showKey: [{ key: 'status', value: status }],
        params: [{ archivesBoxId: 'id' }, { lastStatus: 'status' }],
        state: {
          form: btnForm,
          config: {
            title: '档案盒状态变更',
            width: '760px',
            type: 'layer',
            grid: 12,
            labelCol: 12,
            wrapperCol: 24,
            layout: 'vertical',
            updateUrl: Api.boxUpdateStatus
          }
        }
      };
    };
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'code',
        value: '档案盒编码',
        type: 'slot',
        state: {
          slotName: 'code'
        }
      }),
      new TextTable({
        key: 'boxName',
        value: '档案盒名称'
      }),
      new TextTable({
        key: 'name',
        value: '描述'
      }),
      new TextTable({
        key: 'status',
        value: '档案盒状态',
        type: 'dictionary',
        state: {
          filterName: 'BOX_STATUS'
        },
        colors: BOX_STATUS_COLOR
      }),
      new TextTable({
        key: 'folderName',
        value: '存放地点',
        columns: {
          width: 200
        }
      }),
      new TextTable({
        key: 'spineThickness',
        value: '脊背厚度（cm）'
      }),
      new TextTable({
        key: 'typeName',
        value: '档案类型'
      }),
      new TextTable({
        key: 'startPartNo',
        value: '起始件号'
      }),
      new TextTable({
        key: 'endPartNo',
        value: '终止件号'
      }),
      new TextTable({
        key: 'modifierName',
        value: '修改人'
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间',
        columns: {
          width: 200
        }
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: {
          fixed: 'right',
          width: 100
        },
        handle: [
          {
            type: 'delete',
            url: Api.boxDelBatch,
            text: '删除',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {
              postType: 'post',
              type: 'array'
            },
            showKey: [{ key: 'status', value: 1, invert: false }]
          },
          // 关闭-状态变更
          setAction(0),
          // 使用中-状态变更
          setAction(2)
        ]
      })
    ];
    return tables;
  }
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '添加',
        type: 'primary',
        class: 'icon-add',
        state: {
          type: 'BOX_ADD'
        }
      }),
      new TextTable({
        key: 'delete',
        value: '删除',
        type: 'default',
        class: 'icon-delete',
        state: {
          type: 'array',
          postType: 'post',
          url: Api.boxDelBatch,
          centered: true,
          skipError: true
        }
      }),
      new TextTable({
        key: 'select',
        value: '打印',
        type: 'default',
        state: {
          showLeftIcon: true
        },
        class: 'icon-print',
        options: [
          {
            key: 'local',
            label: '打印卷内目录',
            state: {
              type: 'PRINT_FILE_LIST'
            }
          },
          {
            key: 'local',
            label: '打印案卷目录',
            state: {
              type: 'PRINT_COVER_DIRECTORY'
            }
          },
          {
            key: 'local',
            label: '打印封面',
            state: {
              type: 'PRINT_COVER'
            }
          },
          {
            key: 'local',
            label: '打印脊背',
            state: {
              type: 'PRINT_BACK'
            }
          }
        ]
      }),
      new TextTable({
        key: 'select',
        value: '导出',
        type: 'default',
        options: [
          {
            key: 'download',
            label: '导出选中',
            state: {
              url: Api.boxSelectExport,
              fileName: '档案盒表格.xlsx'
            }
          },
          {
            key: 'download',
            label: '导出全部',
            state: {
              type: 'all',
              url: Api.boxExportAll,
              postType: 'get',
              fileName: '档案盒表格.xlsx'
            }
          }
        ]
      })
    ];
    return icons;
  }
  getPrintQuestions() {
    const questions: QuestionBase<any>[] = [
      new SelectQuestion({
        key: 'spineThickness',
        label: '脊背厚度',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'SPINE_THICKNESS'
        }
      })
    ];
    return questions;
  }
}

export default new HomeService();
